#include <iostream>
#include <cstring>
using std::cout;
using std::endl;

class Student{
public:
    //构造函数
    Student(int num,const char* name,int age):
    _num(num),_name(new char[strlen(name)+1]()),_age(age)
    {
        strcpy(_name,name);
        cout<<"student init"<<endl;
    }
    //打印
    void print(){
        cout<<"num:"<<_num<<" name:"<<_name<<" age:"<<_age<<endl;
    }
    //拷贝构造
    Student(const Student & rhs)
    :_num(rhs._num),_age(rhs._age)
    {
        _name = new char[strlen(rhs._name)+1]();
        strcpy(_name,rhs._name);
        cout<<"Student copy"<<endl;
    }
    ~Student(){
        if(_name){
            delete [] _name;
            _name = nullptr;
        }
    }
private:
    int _num;
    char *_name;
    int _age;
};
Student g_stu = Student(2,"xionger",5);
Student func(){
    return g_stu;
}

void test1(){
    Student stu(1,"xiongda",6);
    stu.print();
    Student stu2 = stu;
    stu2.print();

}
void test2(){
    cout <<"-------------"<<endl;
    func();
}

int main()
{
    //test1();
    test2();
    return 0;
}

